package com.tanhua.app.service;

import com.tanhua.api.UserApi;
import com.tanhua.app.intercept.UserHolder;
import com.tanhua.model.pojo.User;
import com.tanhua.model.vo.HuanXinUserVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HuanXinService {

    @DubboReference
    private UserApi userApi;

    /**
     * 查询用户环信信息
     * @return
     */
    public HuanXinUserVo findHuanXinUser() {
        //1.获取当前用户的id
        Long userId = UserHolder.getUserId();
        //2.通过用户id查询用户信息
        User user = userApi.findByUserId(userId);
        //3.判断,不存在
        if (user == null){
            return null;
        }
        //存在，创建环信对象，封装用户环信信息
        HuanXinUserVo huanXinUserVo = new HuanXinUserVo();
        huanXinUserVo.setUsername(user.getHxUser());
        huanXinUserVo.setPassword(user.getHxPassword());
        return huanXinUserVo;
    }
}
